package com.hunan.api.catv.action.message;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.message.JgPushBiz;
import com.hunan.api.catv.service.biz.smartfamily.SmartFamilyBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description 描述
 * @date 2021/6/21 0021
 * @package com.hunan.api.catv.action.message
 * @company 湖南有线
 */
@RestController
@RequestMapping(Api.message)
public class JgMessageAction extends BaseAction {

    @Autowired
    private JgPushBiz jgPushBiz;
    @Autowired
    private SmartFamilyBiz smartFamilyBiz;

    @PostMapping("/jg/messageGiveBack")
    public Result messageGiveBack(String deviceNo, String msgId) {
        if (ObjectUtils.isEmpty(deviceNo)) {
            return buildRequire("deviceNo required");
        }
        if (ObjectUtils.isEmpty(msgId)) {
            return buildRequire("msgId required");
        }
        return buildOK(jgPushBiz.messageGiveBack(deviceNo, msgId), "");
    }

    @MemberAuth
    @PostMapping("/jg/read")
    public Result readMessage(String msgId, HttpServletRequest request) {
        if (ObjectUtils.isEmpty(msgId)) {
            return buildRequire("msgId required");
        }
        return buildOK(jgPushBiz.readMessage(msgId,getMemberIdV2(request)), "");
    }

    @GetMapping("/jg/page/{pageNum}/{pageSize}/{deviceNo}")
    public Result page(@PathVariable Integer pageNum, @PathVariable Integer pageSize,@PathVariable String deviceNo,HttpServletRequest request) {
        if (ObjectUtils.isEmpty(deviceNo)) {
            return buildRequire("deviceNo required");
        }
        return buildOK(jgPushBiz.page(pageNum,pageSize,getMemberIdV2(request),deviceNo), "");
    }

    @GetMapping("/jg/read/statistics/{deviceNo}")
    public Result readStatistics(@PathVariable String deviceNo,HttpServletRequest request) {
        if (ObjectUtils.isEmpty(deviceNo)) {
            return buildRequire("deviceNo required");
        }
        return buildOK(jgPushBiz.readStatistics(deviceNo,getMemberIdV2(request)), "");
    }

    @MemberAuth
    @GetMapping("/smartFamily/msg/simpleInfo")
    public Result simpleInfo(HttpServletRequest request) {
        return buildOK(smartFamilyBiz.simpleInfo(getMemberIdV2(request)), "");
    }

    @MemberAuth
    @GetMapping("/smartFamily/msg/list/{pageNum}/{pageSize}/{type}")
    public Result simpleInfo(@PathVariable Integer pageNum, @PathVariable Integer pageSize,@PathVariable Integer type,HttpServletRequest request) {
        return buildOK(smartFamilyBiz.msgList(pageNum,pageSize,type,getMemberIdV2(request)), "");
    }

}
